/*
-----------------------------------------------------------------------------
Filename:    DreddWorld.cpp
Modified By: Michael Sebright
-----------------------------------------------------------------------------

This source file is based off of the
   ___                 __    __ _ _    _ 
  /___\__ _ _ __ ___  / / /\ \ (_) | _(_)
 //  // _` | '__/ _ \ \ \/  \/ / | |/ / |
/ \_// (_| | | |  __/  \  /\  /| |   <| |
\___/ \__, |_|  \___|   \/  \/ |_|_|\_\_|
      |___/                              
      Tutorial Framework
      http://www.ogre3d.org/tikiwiki/
-----------------------------------------------------------------------------
*/

#include "DreddWorld.h"
#include "OgreNode.h"
#include "conio.h"


using namespace Ogre;

//-------------------------------------------------------------------------------------
DreddWorld::DreddWorld(void) {
}
//-------------------------------------------------------------------------------------
DreddWorld::~DreddWorld(void) {
}

/*
 * Load scene based on level
 */
void DreddWorld::createScene(int level) {
	switch(level) {
		case 0:
			levelZero();
			break;
		case 1 : 
			levelOne();
			break;
		case 2:
			levelTwo();
			break;
		case 3:
			levelThree();
			break;
		case 4:
			levelFour();
			break;
	}
}

/*
 * Destory scene based on level 
 */
void DreddWorld::destroyScene(int level) {
	switch(level) {
		case 0:
			destroyZero();
			break;
		case 1:
			destroyOne();
			break;
		case 2:
			destroyTwo();
			break;
		case 3:
			destroyThree();
			break;
		case 4:
			destroyFour();
			break;
	}
}

/*
 * Destory enemies 
 */
void DreddWorld::destroyEnemyList() {
	for(std::list<WalkingEnemy*>::iterator it = enemies.begin(); it != enemies.end(); it++) {
		(*it)->mEntity->detachFromParent(); // remove enemy from scene 
		delete (*it); // delete memory
	}

	enemies.clear(); // clear list
}

/*
 * Load level 0
 */
void DreddWorld::levelZero() {
	// Create skybox
	mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox", 1000);

	// create a floor mesh resource
	MeshManager::getSingleton().createPlane("floor", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
		Plane(Vector3::UNIT_Y, 0), 2000, 2000, 200, 200, true, 1, 200, 200, Vector3::UNIT_Z);

	// create a floor entity, give it a material, and place it at the origin
	Entity* floor = mSceneMgr->createEntity("Floor", "floor");
	floor->setMaterialName("Examples/Rockwall");
	floor->setCastShadows(false);
	mSceneMgr->getRootSceneNode()->attachObject(floor);

	// create gate mesh resource
	MeshManager::getSingleton().createPlane("gate", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
		MovablePlane(Vector3::UNIT_Z, -100), 50, 50, 5, 5, true, 1, 5, 5, Vector3::UNIT_Y);

	// Create gate entity with BumpyMetal texture
	Entity* gate = mSceneMgr->createEntity("Gate", "gate");
	gate->setMaterialName("Examples/BumpyMetal");
	gate->setCastShadows(false);

	SceneNode* gateNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("GateNode");
	gateNode->attachObject(gate);

	// create building mesh resource
	MeshManager::getSingleton().createPlane("building", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
		Plane(Vector3::UNIT_Z, -100), 150, 510, 15, 51, true, 1, 15, 51, Vector3::UNIT_Y);

	// Create front portion of building 
	Entity* buildingFrontRight = mSceneMgr->createEntity("BuildingFrontRight", "building");
	Entity* buildingFrontLeft = mSceneMgr->createEntity("BuildingFrontLeft", "building");
	Entity* buildingFrontMiddle = mSceneMgr->createEntity("BuildingFrontMiddle", "building");
	buildingFrontRight->setMaterialName("sibenik/rozetaTwoSide");
	buildingFrontRight->setCastShadows(false);
	buildingFrontLeft->setMaterialName("sibenik/rozetaTwoSide");
	buildingFrontLeft->setCastShadows(false);
	buildingFrontMiddle->setMaterialName("sibenik/rozetaTwoSide");
	buildingFrontMiddle->setCastShadows(false);

	SceneNode* buildingNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("buildingNode");
	SceneNode* buildingFrontLeftNode = buildingNode->createChildSceneNode("buildingFrontLeftNode");
	SceneNode* buildingFrontRightNode = buildingNode->createChildSceneNode("buildingFrontRightNode");
	SceneNode* buildingFrontMiddleNode = buildingNode->createChildSceneNode("buildingFrontMiddleNode");
	
	buildingFrontRightNode->translate(Vector3::Vector3(100.0, -230.0, 0.0), Node::TS_PARENT);
	buildingFrontRightNode->attachObject(buildingFrontRight);
	
	buildingFrontLeftNode->translate(Vector3::Vector3(-100.0, -230.0, 0.0), Node::TS_PARENT);
	buildingFrontLeftNode->attachObject(buildingFrontLeft);

	buildingFrontMiddleNode->scale((7.0f/3.0f), 1.0f, 1.0f);
	buildingFrontMiddleNode->translate(Vector3::Vector3(0.0,280,0.0));
	buildingFrontMiddleNode->attachObject(buildingFrontMiddle);

	// Create Left Right and rear of building 
	Entity* buildingRight = mSceneMgr->createEntity("BuildingRight", "building");
	Entity* buildingLeft = mSceneMgr->createEntity("BuildingLeft", "building");
	Entity* buildingRear = mSceneMgr->createEntity("BuildingRear", "building");
	buildingRight->setMaterialName("sibenik/rozetaTwoSide");
	buildingRight->setCastShadows(false);
	buildingLeft->setMaterialName("sibenik/rozetaTwoSide");
	buildingLeft->setCastShadows(false);
	buildingRear->setMaterialName("sibenik/rozetaTwoSide");
	buildingRear->setCastShadows(false);

	SceneNode* buildingLeftNode = buildingNode->createChildSceneNode("buildingLeftNode");
	SceneNode* buildingRightNode = buildingNode->createChildSceneNode("buildingRightNode");
	SceneNode* buildingRearNode = buildingNode->createChildSceneNode("buildingRearNode");

		
	buildingLeftNode->rotate(Vector3::UNIT_Y, Radian::Radian(Degree::Degree(90)), Node::TS_PARENT);
	buildingLeftNode->translate(-75.0f, 25.0f, -325.0f, Node::TS_PARENT);
	buildingLeftNode->scale(3.0f, 2.0f, 1.0f);
	buildingLeftNode->attachObject(buildingLeft);

	buildingRightNode->rotate(Vector3::UNIT_Y, Radian::Radian(Degree::Degree(-90)), Node::TS_PARENT);
	buildingRightNode->translate(75.0f, 25.0f, -325.0f, Node::TS_PARENT);
	buildingRightNode->scale(3.0, 2.0, 1.0);
	buildingRightNode->attachObject(buildingRight);

	buildingRearNode->translate(0.0f, 25.0f, -450.0f, Node::TS_PARENT);
	buildingRearNode->scale((7.0f/3.0f), 2.0f, 1.0f);
	buildingRearNode->attachObject(buildingRear);

	// Create top of building leaving slit open for natural light
	Entity* buildingTopRight = mSceneMgr->createEntity("BuildingTopRight", "building");
	buildingTopRight->setMaterialName("sibenik/rozetaTwoSide");
	buildingTopRight->setCastShadows(false);

	SceneNode* buildingTopRightNode = buildingNode->createChildSceneNode("buildingTopRightNode");

	buildingTopRightNode->rotate(Vector3::UNIT_X, Radian::Radian(Degree::Degree(90)), Node::TS_PARENT);
	buildingTopRightNode->translate(0.0, 435.0, -325.0);
	buildingTopRightNode->scale((7.0f/3.0f), (450.0f/510.0f), 1.0);
	buildingTopRightNode->attachObject(buildingTopRight);


	enemies.push_back(new WalkingEnemy(mCamera));
	enemyCount = 1;
	// Set the scene's ambient light
	mSceneMgr->setAmbientLight(ColourValue(0.5f, 0.5f, 0.5f));

	// Create a Light and set its position
	Light* light = mSceneMgr->createLight("MainLight");
	light->setPosition(20.0f, 80.0f, 50.0f);

	destination = Vector3(0, 0, -100); // set final destination 

	mCharacter->setPosition(Vector3::Vector3(0,5.5,0), Quaternion::Quaternion(1,0,-1,0)); // set position of dredd
}

/*
 * Load Level One 
 */
void DreddWorld::levelOne() {
	enemyCount = 54; // set enemy count 
	destination = Vector3(0, 0, -1900); // set final destination 
	
	/* create floor mesh */
	MeshManager::getSingleton().createPlane("floor", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
		Plane(Vector3::UNIT_Y, 0), 200, 200, 20, 20, true, 1, 20, 20, Vector3::UNIT_Z);

	/* create wall mesh */
	MeshManager::getSingleton().createPlane("wall", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
		Plane(Vector3::UNIT_X, 0), 2000, 200, 200, 20, true, 1, 200, 20, Vector3::UNIT_Y);

	/* create nodes for objects */
	SceneNode* floorNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("FloorNode");
	SceneNode* leftWallNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("LeftWallNode");
	SceneNode* rightWallNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("RightWallNode");
	SceneNode* rearWallNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("RearWallNode");
	SceneNode* gateNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("GateNode");

	/* create enities for objects */
	Entity* floor = mSceneMgr->createEntity("Floor", "floor");
	Entity* leftWall = mSceneMgr->createEntity("LeftWall", "wall");
	Entity* rightWall = mSceneMgr->createEntity("RightWall", "wall");
	Entity* rearWall = mSceneMgr->createEntity("RearWall", "wall");
	Entity* gate = mSceneMgr->createEntity("Gate", "gate");

	/* set textures for objects */
	floor->setMaterialName("Panels");
	leftWall->setMaterialName("sibenik/kuce/test");
	rightWall->setMaterialName("sibenik/kuce/test");
	rearWall->setMaterialName("sibenik/kuce/test");
	gate->setMaterialName("Examples/BumpyMetal");

	/* set shadow casting */
	floor->setCastShadows(false);
	leftWall->setCastShadows(false);
	rightWall->setCastShadows(true);
	rearWall->setCastShadows(false);
	gate->setCastShadows(false);

	/* attach to nodes and make visible */
	floorNode->attachObject(floor);
	leftWallNode->attachObject(leftWall);
	rightWallNode->attachObject(rightWall);
	rearWallNode->attachObject(rearWall);
	gateNode->attachObject(gate);

	/* Move to desired location */
	floorNode->translate(0,0,-900);
	leftWallNode->translate(-100, 0, -900);
	rightWallNode->yaw(Radian::Radian(Degree::Degree(180)));
	rightWallNode->translate(100, 0, -900);
	rearWallNode->yaw(Radian::Radian(Degree::Degree(-90)));
	rearWallNode->translate(0, 0, -1900);
	gateNode->translate(0,0,-1798.0);

	/* create barrels */
	SceneNode* barrelNode;
	Entity* barrel;
	int i;
	for(i = 0; i < 9; i++) { 

		/* Create left barrel on left side */
		barrelNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("BarrelNode" + Ogre::StringConverter::toString(((i * 6) + 1)));
		barrel = mSceneMgr->createEntity("Barrel" + Ogre::StringConverter::toString(((i * 6) + 1)), "Barrel.mesh");
		barrelNode->attachObject(barrel);
		barrelNode->scale(2,2,2);
		barrelNode->translate(-94, 6, -100 - (200* i));

		/* create right barrel on left side */
		barrelNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("BarrelNode" + Ogre::StringConverter::toString(((i * 6) + 2)));
		barrel = mSceneMgr->createEntity("Barrel" + Ogre::StringConverter::toString(((i * 6) + 2)), "Barrel.mesh");
		barrelNode->attachObject(barrel);
		barrelNode->scale(2,2,2);
		barrelNode->translate(-94, 6, -110 - (200 * i));

		/* create middle barrel on left side */
		barrelNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("BarrelNode" + Ogre::StringConverter::toString(((i * 6) + 3)));
		barrel = mSceneMgr->createEntity("Barrel" + Ogre::StringConverter::toString(((i * 6) + 3)), "Barrel.mesh");
		barrelNode->attachObject(barrel);
		barrelNode->scale(2,2,2);
		barrelNode->translate(-94, 18, -107.5 - (200 * i));

		/* create right barrel on right side */
		barrelNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("BarrelNode" + Ogre::StringConverter::toString(((i * 6) + 4)));
		barrel = mSceneMgr->createEntity("Barrel" + Ogre::StringConverter::toString(((i * 6) + 4)), "Barrel.mesh");
		barrelNode->attachObject(barrel);
		barrelNode->scale(2,2,2);
		barrelNode->translate(94, 6, -100 - (200 * i));

		/* cerate left barrel on right side */
		barrelNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("BarrelNode" + Ogre::StringConverter::toString(((i * 6) + 5)));
		barrel = mSceneMgr->createEntity("Barrel" + Ogre::StringConverter::toString(((i * 6) + 5)), "Barrel.mesh");
		barrelNode->attachObject(barrel);
		barrelNode->scale(2,2,2);
		barrelNode->translate(94, 6, -110 - (200 * i));

		/*create middle barrel on right side */
		barrelNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("BarrelNode" + Ogre::StringConverter::toString(((i * 6) + 6)));
		barrel = mSceneMgr->createEntity("Barrel" + Ogre::StringConverter::toString(((i * 6) + 6)), "Barrel.mesh");
		barrelNode->attachObject(barrel);
		barrelNode->scale(2,2,2);
		barrelNode->translate(94, 18, -107.5 - (200 * i));

		/* add enemy behind left and right barrel respectivly */
		enemies.push_back(new WalkingEnemy(mCamera, Vector3::Vector3(-94,0, -115 - (200 * i))));
		enemies.push_back(new WalkingEnemy(mCamera, Vector3::Vector3(94,0,  -115 - (200 * i))));
	}

	/* create pallets */
	SceneNode* palletNode;
	Entity* pallet;
	for(i = 0; i < 5; i++) { 
		/* create two pallets on right side of screen */
		palletNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("PalletNode" + Ogre::StringConverter::toString(((i * 4) + 1)));
		pallet = mSceneMgr->createEntity("Pallet" + Ogre::StringConverter::toString(((i * 4) + 1)), "WoodPallet.mesh");
		palletNode->attachObject(pallet);
		palletNode->scale(3, 3, 3);
		palletNode->translate(88.0f, 2.0f, -200.0f - (400.0f * i));
		palletNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("PalletNode" + Ogre::StringConverter::toString(((i * 4) + 2)));
		pallet = mSceneMgr->createEntity("Pallet" + Ogre::StringConverter::toString(((i * 4) + 2)), "WoodPallet.mesh");
		palletNode->attachObject(pallet);
		palletNode->scale(3, 3, 3);
		palletNode->rotate(Vector3::UNIT_Z, Radian::Radian(Degree::Degree(45)));
		palletNode->translate(88.0f, 11.0f, -200.0f - (400.0f * i));

		/* create two pallets on left side of teh screen */
		palletNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("PalletNode" + Ogre::StringConverter::toString(((i * 4) + 3)));
		pallet = mSceneMgr->createEntity("Pallet" + Ogre::StringConverter::toString(((i * 4) + 3)), "WoodPallet.mesh");
		palletNode->attachObject(pallet);
		palletNode->scale(3, 3, 3);
		palletNode->translate(-88.0f, 2.0f, -400.0f - (400.0f * i));
		palletNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("PalletNode" + Ogre::StringConverter::toString(((i * 4) + 4)));
		pallet = mSceneMgr->createEntity("Pallet" + Ogre::StringConverter::toString(((i * 4) + 4)), "WoodPallet.mesh");
		palletNode->attachObject(pallet);
		palletNode->scale(3, 3, 3);
		palletNode->rotate(Vector3::UNIT_Z, Radian::Radian(Degree::Degree(-45)));
		palletNode->translate(-88.0f, 11.0f, -400.0f - (400.0f * i));
	}

	/* load enmies */
	for(i = 1; i < 5; i++) {
		enemies.push_back(new WalkingEnemy(mCamera, Vector3::Vector3(-75, 0, -475 * i)));
		enemies.push_back(new WalkingEnemy(mCamera, Vector3::Vector3(-50, 0, -475 * i)));
		enemies.push_back(new WalkingEnemy(mCamera, Vector3::Vector3(-25, 0, -475 * i)));
		enemies.push_back(new WalkingEnemy(mCamera, Vector3::Vector3(0, 0, -475 * i)));
		enemies.push_back(new WalkingEnemy(mCamera, Vector3::Vector3(25, 0, -475 * i)));
		enemies.push_back(new WalkingEnemy(mCamera, Vector3::Vector3(50, 0, -475 * i)));
		enemies.push_back(new WalkingEnemy(mCamera, Vector3::Vector3(75, 0, -475 * i)));
	}

	/* load more enemies */
	enemies.push_back(new WalkingEnemy(mCamera, Vector3::Vector3(-94, 0, -1800)));
	enemies.push_back(new WalkingEnemy(mCamera, Vector3::Vector3(-94, 0, -1825)));
	enemies.push_back(new WalkingEnemy(mCamera, Vector3::Vector3(-94, 0, -1850)));
	enemies.push_back(new WalkingEnemy(mCamera, Vector3::Vector3(-94, 0, -1875)));
	enemies.push_back(new WalkingEnemy(mCamera, Vector3::Vector3(94, 0, -1800)));
	enemies.push_back(new WalkingEnemy(mCamera, Vector3::Vector3(94, 0, -1825)));
	enemies.push_back(new WalkingEnemy(mCamera, Vector3::Vector3(94, 0, -1850)));
	enemies.push_back(new WalkingEnemy(mCamera, Vector3::Vector3(94, 0, -1875)));

	/* set lighting for scene */
	Light* light = mSceneMgr->createLight("MainLight");
	light->setPosition(0.0f, 80.0f, 50.0f);
	light->setDiffuseColour(ColourValue::ColourValue(1,1,1,1));

	/* set character position */
	mCharacter->setPosition(Vector3::Vector3(0,5.5,0), Quaternion::Quaternion(1,0,-1,0));

}

/*
 * Load level 2
 * Enemies are handled by a counter in DreddGame
 */
void DreddWorld::levelTwo() {
	enemyCount = 80;
	destination = Vector3(0, 0, -200);

	mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox", 1000);

	/* create floor mesh */
	MeshManager::getSingleton().createPlane("floor", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
		Plane(Vector3::UNIT_Y, 0), 500, 500, 50, 50, true, 1, 50, 50, Vector3::UNIT_Z);

	/* create wall mesh */
	MeshManager::getSingleton().createPlane("wall", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
		Plane(Vector3::UNIT_X, 0), 500, 200, 50, 20, true, 1, 50, 20, Vector3::UNIT_Y);

	// create gate mesh resource
	MeshManager::getSingleton().createPlane("gate", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
		Plane(Vector3::UNIT_Z, -100), 50, 50, 5, 5, true, 1, 5, 5, Vector3::UNIT_Y);

	/* create nodes for objects */
	SceneNode* floorNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("FloorNode");
	SceneNode* leftWallNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("LeftWallNode");
	SceneNode* rightWallNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("RightWallNode");
	SceneNode* rearWallNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("RearWallNode");
	SceneNode* gateNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("GateNode");

	/* create enities for objects */
	Entity* floor = mSceneMgr->createEntity("Floor", "floor");
	Entity* leftWall = mSceneMgr->createEntity("LeftWall", "wall");
	Entity* rightWall = mSceneMgr->createEntity("RightWall", "wall");
	Entity* rearWall = mSceneMgr->createEntity("RearWall", "wall");
	Entity* gate = mSceneMgr->createEntity("Gate", "gate");

	/* set textures */
	floor->setMaterialName("Panels");
	leftWall->setMaterialName("sibenik/kuce/test");
	rightWall->setMaterialName("sibenik/kuce/test");
	rearWall->setMaterialName("sibenik/kuce/test");
	gate->setMaterialName("Examples/BumpyMetal");

	/* set shadow casting */
	floor->setCastShadows(false);
	leftWall->setCastShadows(false);
	rightWall->setCastShadows(true);
	rearWall->setCastShadows(false);
	gate->setCastShadows(false);

	/* attach objects and make visible */
	floorNode->attachObject(floor);
	leftWallNode->attachObject(leftWall);
	rightWallNode->attachObject(rightWall);
	rearWallNode->attachObject(rearWall);
	gateNode->attachObject(gate);

	/* move to desired locatoin */
	floorNode->translate(0,0,-100);
	leftWallNode->translate(-100, 0, -100);
	rightWallNode->yaw(Radian::Radian(Degree::Degree(180)));
	rightWallNode->translate(100, 0, -100);
	rearWallNode->yaw(Radian::Radian(Degree::Degree(-90)));
	rearWallNode->translate(0, 0, -200);
	rearWallNode->scale(0.8, 1, 1);
	gateNode->translate(0,0,-100.0);

	/* set main lighting */
	Light* light = mSceneMgr->createLight("MainLight");
	light->setPosition(0.0f, 80.0f, 50.0f);
	light->setDiffuseColour(ColourValue::ColourValue(1,1,1,1));

	/* set character position */
	mCharacter->setPosition(Vector3::Vector3(0,5.5,0), Quaternion::Quaternion(1,0,-1,0));
	mCharacter->setLives(mCharacter->getLives());
}

/*
 * Load level 3
 */
void DreddWorld::levelThree() {
	
}

/*
 * Load level 4
 */
void DreddWorld::levelFour() {
	
}

/*
 * Destroy level 0
 */
void DreddWorld::destroyZero() {
	/* delete entities */
	mSceneMgr->destroyEntity("Gate");
	mSceneMgr->destroyEntity("Floor");
	mSceneMgr->destroyEntity("BuildingFrontRight");
	mSceneMgr->destroyEntity("BuildingFrontLeft");
	mSceneMgr->destroyEntity("BuildingFrontMiddle");
	mSceneMgr->destroyEntity("BuildingRight");
	mSceneMgr->destroyEntity("BuildingLeft");
	mSceneMgr->destroyEntity("BuildingRear");
	mSceneMgr->destroyEntity("BuildingTopRight");

	/* Delete Nodes */
	mSceneMgr->getRootSceneNode()->removeAndDestroyChild("GateNode");
	mSceneMgr->getRootSceneNode()->removeAndDestroyChild("buildingNode");

	mSceneMgr->destroyLight("MainLight"); // delete light

	destroyEnemyList(); // delete enemies 
}

/*
 * Destroy level 1
 */
void DreddWorld::destroyOne() {
	int i;
	/* delete entities */
	mSceneMgr->destroyEntity("Floor");
	mSceneMgr->destroyEntity("LeftWall");
	mSceneMgr->destroyEntity("RightWall");
	mSceneMgr->destroyEntity("RearWall");
	mSceneMgr->destroyEntity("Gate");
	for(i = 1; i < 54; i++) { 
		mSceneMgr->destroyEntity("Barrel" + Ogre::StringConverter::toString(i)); 
	}
	for(i = 1; i < 21; i++) { 
		mSceneMgr->destroyEntity("Pallet" + Ogre::StringConverter::toString(i));
	}

	/* Delete Nodes */
	mSceneMgr->getRootSceneNode()->removeAndDestroyChild("FloorNode");
	mSceneMgr->getRootSceneNode()->removeAndDestroyChild("LeftWallNode");
	mSceneMgr->getRootSceneNode()->removeAndDestroyChild("RightWallNode");
	mSceneMgr->getRootSceneNode()->removeAndDestroyChild("RearWallNode");
	mSceneMgr->getRootSceneNode()->removeAndDestroyChild("GateNode");
	for(i = 1; i < 54; i++) { 
		mSceneMgr->getRootSceneNode()->removeAndDestroyChild("BarrelNode" + Ogre::StringConverter::toString(i));
	}
	for(i = 1; i < 21; i++) {
		mSceneMgr->getRootSceneNode()->removeAndDestroyChild("PalletNode" + Ogre::StringConverter::toString(i));
	}

	mSceneMgr->destroyLight("MainLight"); // delete light

	destroyEnemyList(); // destroy enemies 
}

/*
 * Destroy level 2
 */
void DreddWorld::destroyTwo() {
	/* delete entities */
	mSceneMgr->destroyEntity("Floor");
	mSceneMgr->destroyEntity("LeftWall");
	mSceneMgr->destroyEntity("RightWall");
	mSceneMgr->destroyEntity("RearWall");
	mSceneMgr->destroyEntity("Gate");

	/* Delete Nodes */
	mSceneMgr->getRootSceneNode()->removeAndDestroyChild("FloorNode");
	mSceneMgr->getRootSceneNode()->removeAndDestroyChild("LeftWallNode");
	mSceneMgr->getRootSceneNode()->removeAndDestroyChild("RightWallNode");
	mSceneMgr->getRootSceneNode()->removeAndDestroyChild("RearWallNode");
	mSceneMgr->getRootSceneNode()->removeAndDestroyChild("GateNode");

	mSceneMgr->destroyLight("MainLight"); // delete light

	destroyEnemyList(); // delete enemies 
}

/*
 * Destroy level 3
 */
void DreddWorld::destroyThree() {

}

/*
 * Destroy level 4
 */
void DreddWorld::destroyFour() {

}


#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
#endif

#ifdef __cplusplus
extern "C" {
#endif

#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
    INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
    int main(int argc, char *argv[])
#endif
    {
        // Create application object
        DreddWorld app;

        try {
            app.go();
        } catch( Ogre::Exception& e ) {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
            MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
            std::cerr << "An exception has occured: " <<
                e.getFullDescription().c_str() << std::endl;
#endif
        }

    }

#ifdef __cplusplus
}
#endif
